package com.ganbo.stock.service.impl;

import com.ganbo.stock.entity.ReleaseBan;
import com.ganbo.stock.enums.ServiceType;
import com.ganbo.stock.repository.ReleaseBanRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 解禁(以当前交易日的前后15天左右为时间范围，已经进行或者即将进行的解禁限售行为)
 * Created by gan on 2020/12/28 21:14.
 */

@Service
public class ReleaseBanService extends BaseService {

    @Autowired
    ReleaseBanRepository releaseBanRepository;


    public void fetchTodayReleaseBanStockInfo() {
        Date now = new Date();
        List<ReleaseBan> releaseBansDb = releaseBanRepository.findByRecordDate(now);
        if (!CollectionUtils.isEmpty(releaseBansDb)) return;

        List<ReleaseBan> releaseBans = sendReqReturnList(ServiceType.RELEASE_BAN, new HashMap<String, String>(), ReleaseBan.class);
        if (CollectionUtils.isEmpty(releaseBans)) return;

        for (ReleaseBan releaseBan : releaseBans) {
            releaseBan.setRecordDate(now);
            releaseBanRepository.save(releaseBan);
        }
    }


}
